import webbrowser
import pickle

def write_dump(l): 
    test_file = open('auto_browse.txt','wb')
    pickle.dump(l, test_file)
    test_file.close
    
def read_dump():
    test_file = open('auto_browse.txt','rb')
    ret = pickle.load(test_file)
    test_file.close()
    return ret
    
def append_dump(l):
    current = read_dump()
    current.append(l)
    write_dump(current)
    

def browse_sites():
    sites = read_dump()
    # sites.reverse()
    count = 0
    for s in sites:
        print '    opening: ' + s
        webbrowser.open(s)
        count += 1
        if divmod(count,3)[1] == 0:
            a = raw_input('        continue? (y/n)...')
            if not a == 'y':
#                print 'exiting press any key...'
#                raw_input()
                break
#    print 'Auto browse complete. Press any key...'
#    raw_input()
        
        
           
    


def read_pickle():
    pass
    
if __name__ == '__main__':
#    l = ['www.google.com',
#     'www.yahoo.co.uk',
#     'www.bbc.co.uk']
#    write_dump(l)
#    print 10, read_dump()
#    append_dump('www.reddit2.com')
#    print 20, read_dump()
    browse_sites()
    